/*
 * Copyright 2002-2017 the original author or authors.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      https://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package org.springframework.beans.factory.support;

import org.springframework.beans.factory.BeanDefinitionStoreException;
import org.springframework.core.io.Resource;
import org.springframework.core.io.ResourceLoader;
import org.springframework.lang.Nullable;

/**
 * Simple interface for bean definition readers.
 * Specifies load methods with Resource and String location parameters.
 *
 * <p>Concrete bean definition readers can of course add additional
 * load and register methods for bean definitions, specific to
 * their bean definition format.
 *
 * <p>Note that a bean definition reader does not have to implement
 * this interface. It only serves as suggestion for bean definition
 * readers that want to follow standard naming conventions.
 *
 * @author Juergen Hoeller
 * @since 1.1
 * @see org.springframework.core.io.Resource
 */

/**
 2方法
 BeanDefinitionRegistry getRegistry() 返回用于注册Bean定义的Bean工厂，通过BeanDefinitionRegistry接口封装了处理Bean定义的相关方法
 ResourceLoader getResourceLoader() 返回用于资源定位的ResourceLoader，可用于加载多个资源（如果实现了ResourcePatternResolver接口）
 ClassLoader getBeanClassLoader() 返回用于加载Bean类的ClassLoader，null值表示不急于加载Bean类
 BeanNameGenerator getBeanNameGenerator() 返回用于匿名Bean（未显式指定名称的Bean）的Bean名称生成器
 int loadBeanDefinitions(Resource resource) 从指定的Resource资源描述符加载Bean定义，返回找到的Bean定义数量
 int loadBeanDefinitions(Resource... resources) 从指定的Resource资源描述符数组加载Bean定义，返回找到的Bean定义数量
 int loadBeanDefinitions(String location) 从指定的资源位置字符串加载Bean定义，位置可以是模式（如果ResourceLoader实现了ResourcePatternResolver），返回找到的Bean定义数量
 int loadBeanDefinitions(String... locations) 从指定的资源位置字符串数组加载Bean定义，返回找到的Bean定义数量

 3. 与其他类和接口的关系
 子类
 AbstractBeanDefinitionReader:
	 这是一个抽象类，实现了 BeanDefinitionReader 接口的大部分通用功能。
	 它提供了 registry、resourceLoader、beanClassLoader 和 beanNameGenerator 属性的存储和基本管理。
	 它实现了 loadBeanDefinitions(Resource...)、loadBeanDefinitions(String) 和 loadBeanDefinitions(String...) 方法的基本逻辑，例如处理资源数组和位置字符串，并将实际的加载工作委托给抽象方法 loadBeanDefinitions(Resource)。
	 它还提供了 setResourceLoader 和 setBeanClassLoader 等 setter 方法，允许在创建 reader 后配置这些属性。
	 这个抽象类是大多数具体 Bean 定义读取器的基类。
 XmlBeanDefinitionReader:
	 这是最常用的 BeanDefinitionReader 实现之一。
	 它继承自 AbstractBeanDefinitionReader。
	 它专门用于从 XML 格式的配置文件中加载 Bean 定义。
	 它实现了 loadBeanDefinitions(Resource) 抽象方法，使用 DOM 或 SAX 解析器解析 XML 文件，并根据 Spring 的 XML 配置语义注册 Bean 定义。
 PropertiesBeanDefinitionReader:
	 这个实现类继承自 AbstractBeanDefinitionReader。
	 它用于从 Java Properties 文件中加载 Bean 定义。
	 Properties 文件中的键值对被解析为 Bean 的属性和值。
	 GroovyBeanDefinitionReader:
	 这个实现类继承自 AbstractBeanDefinitionReader。
	 它用于从 Groovy 脚本文件中加载 Bean 定义。
	 Groovy 脚本可以直接定义 Bean 实例或使用 Spring 的 Groovy DSL。

 相关类
	 BeanDefinitionRegistry: 用于注册Bean定义的核心接口
	 ResourceLoader: 用于加载资源的接口
	 ResourcePatternResolver: 扩展ResourceLoader，支持模式匹配
	 BeanNameGenerator: 用于生成Bean名称的策略接口
	 Resource: Spring资源抽象
	 BeanDefinition: Bean定义的抽象表示
	 BeanDefinitionStoreException: Bean定义存储异常
 4. 总结
	 BeanDefinitionReader 是一个简单的接口，定义了Bean定义读取器的标准方法。主要特点包括：
	 提供了统一的Bean定义加载接口
	 支持从不同类型的资源（Resource、位置字符串）加载Bean定义
	 与Spring的资源抽象体系紧密集成
	 定义了必要的组件访问方法（注册器、资源加载器、类加载器、名称生成器）
	 是Spring容器初始化过程中Bean定义加载的核心接口
 5. 应用场景
	 XML配置加载: 通过XmlBeanDefinitionReader加载XML格式的Bean定义
	 Properties配置加载: 通过PropertiesBeanDefinitionReader加载属性文件格式的Bean定义
	 Groovy配置加载: 通过GroovyBeanDefinitionReader加载Groovy脚本中的Bean定义
	 应用程序上下文实现: 被各种ApplicationContext实现用于加载Bean定义
	 自定义配置格式: 可以扩展实现支持其他配置格式的Bean定义加载
 */
public interface BeanDefinitionReader {

	/**
	 * Return the bean factory to register the bean definitions with.
	 * <p>The factory is exposed through the BeanDefinitionRegistry interface,
	 * encapsulating the methods that are relevant for bean definition handling.
	 */
	BeanDefinitionRegistry getRegistry();

	/**
	 * Return the resource loader to use for resource locations.
	 * Can be checked for the <b>ResourcePatternResolver</b> interface and cast
	 * accordingly, for loading multiple resources for a given resource pattern.
	 * <p>A {@code null} return value suggests that absolute resource loading
	 * is not available for this bean definition reader.
	 * <p>This is mainly meant to be used for importing further resources
	 * from within a bean definition resource, for example via the "import"
	 * tag in XML bean definitions. It is recommended, however, to apply
	 * such imports relative to the defining resource; only explicit full
	 * resource locations will trigger absolute resource loading.
	 * <p>There is also a {@code loadBeanDefinitions(String)} method available,
	 * for loading bean definitions from a resource location (or location pattern).
	 * This is a convenience to avoid explicit ResourceLoader handling.
	 * @see #loadBeanDefinitions(String)
	 * @see org.springframework.core.io.support.ResourcePatternResolver
	 */
	@Nullable
	ResourceLoader getResourceLoader();

	/**
	 * Return the class loader to use for bean classes.
	 * <p>{@code null} suggests to not load bean classes eagerly
	 * but rather to just register bean definitions with class names,
	 * with the corresponding Classes to be resolved later (or never).
	 */
	@Nullable
	ClassLoader getBeanClassLoader();

	/**
	 * Return the BeanNameGenerator to use for anonymous beans
	 * (without explicit bean name specified).
	 */
	BeanNameGenerator getBeanNameGenerator();


	/**
	 * Load bean definitions from the specified resource.
	 * @param resource the resource descriptor
	 * @return the number of bean definitions found
	 * @throws BeanDefinitionStoreException in case of loading or parsing errors
	 */
	int loadBeanDefinitions(Resource resource) throws BeanDefinitionStoreException;

	/**
	 * Load bean definitions from the specified resources.
	 * @param resources the resource descriptors
	 * @return the number of bean definitions found
	 * @throws BeanDefinitionStoreException in case of loading or parsing errors
	 */
	int loadBeanDefinitions(Resource... resources) throws BeanDefinitionStoreException;

	/**
	 * Load bean definitions from the specified resource location.
	 * <p>The location can also be a location pattern, provided that the
	 * ResourceLoader of this bean definition reader is a ResourcePatternResolver.
	 * @param location the resource location, to be loaded with the ResourceLoader
	 * (or ResourcePatternResolver) of this bean definition reader
	 * @return the number of bean definitions found
	 * @throws BeanDefinitionStoreException in case of loading or parsing errors
	 * @see #getResourceLoader()
	 * @see #loadBeanDefinitions(org.springframework.core.io.Resource)
	 * @see #loadBeanDefinitions(org.springframework.core.io.Resource[])
	 */
	int loadBeanDefinitions(String location) throws BeanDefinitionStoreException;

	/**
	 * Load bean definitions from the specified resource locations.
	 * @param locations the resource locations, to be loaded with the ResourceLoader
	 * (or ResourcePatternResolver) of this bean definition reader
	 * @return the number of bean definitions found
	 * @throws BeanDefinitionStoreException in case of loading or parsing errors
	 */
	int loadBeanDefinitions(String... locations) throws BeanDefinitionStoreException;

}
